package 滑动;

public class _2379得到K个黑块的最少涂色次数 {
    //我的做法是黑色最多，题解是白色最少效果一样
    public static int minimumRecolors(String blocks, int k) {
        int max=0;
        int c=0;
        char[] charArray = blocks.toCharArray();
        for (int i = 0; i < charArray.length; i++) {
            if(charArray[i]=='B'){
                c++;
            }
            if(i<k-1){
                continue;
            }
            max = Math.max(max, c);
            if(charArray[i-k+1]=='B'){
                c--;
            }
        }
        if(max>k){
            return 0;
        }

        return k-max;
    }

    public static void main(String[] args) {
        //WBBWWBBWBW    k=7
        System.out.println(minimumRecolors("WBBWWBBWBW", 7));
    }
}
